package 创建型模型.原型模式;

import java.io.*;
import java.util.Date;

/**
 * 通过序列化和反序列化也可以实现深复制
 */
public class Client2 implements Serializable {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Date d=new Date(1212931L);
        Sheep s1=new Sheep("呵呵",d);
        //序列化
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
        objectOutputStream.writeObject(s1);
        byte[] bytes = bos.toByteArray();
        //反序列化
        ByteArrayInputStream bis=new ByteArrayInputStream(bytes);
        ObjectInputStream objectInputStream = new ObjectInputStream(bis);
        Sheep s2= (Sheep) objectInputStream.readObject();//克隆好的对象
    }
}
